<html>
<head><meta charset="utf-8"><title>Working of Cargo Clippy fix · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Working.20of.20Cargo.20Clippy.20fix.html">Working of Cargo Clippy fix</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233455785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Working%20of%20Cargo%20Clippy%20fix/near/233455785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BaSh <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Working.20of.20Cargo.20Clippy.20fix.html#233455785">(Apr 07 2021 at 09:14)</a>:</h4>
<p>I would like to know how does cargo Clippy fix works. Is there any RFC/ documentation for that? I'm interested in knowing whether it does AST mut_visit and does the modification or applies a diff patch.</p>



<a name="233486954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Working%20of%20Cargo%20Clippy%20fix/near/233486954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Working.20of.20Cargo.20Clippy.20fix.html#233486954">(Apr 07 2021 at 13:28)</a>:</h4>
<p><code>cargo fix</code> (and <code>cargo clippy --fix</code>) work by running <code>cargo check</code> and capturing the compiler JSON output.  That output includes "suggested_replacement" fields which are simply strings to replace given a range of bytes.  At its core, rustfix just takes a string and a range of bytes, and replaces the content there.  These replacements are (usually) the same that you see in the human-readable output (the "help:" messages).</p>
<p>Some docs if you're interested:</p>
<ul>
<li><a href="https://doc.rust-lang.org/rustc/json.html">https://doc.rust-lang.org/rustc/json.html</a> The JSON format which also discusses things like the "suggestion_applicability" field.</li>
<li><a href="https://rustc-dev-guide.rust-lang.org/diagnostics.html#suggestions">https://rustc-dev-guide.rust-lang.org/diagnostics.html#suggestions</a> discusses how to implement compiler suggestions.</li>
</ul>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>